<template>
<div>
    <div id="formDiv">
   <el-form :model="user" label-width="80px">
       <el-form-item label="用户名">
            <el-input v-model="user.name"></el-input>
        </el-form-item>


        <el-form-item label="密码">
            <el-input v-model="user.password" type='password'></el-input>
        </el-form-item>
  
        <el-form-item>
            <el-button type="primary" @click="lgoin">登录</el-button>
            <el-button>注册</el-button>
        </el-form-item>
   </el-form>
    </div>
</div>
</template>

<style>
#formDiv {
  width: 400px;
}
</style>

<script>
import axios from "axios"

export default {
  data: function() {
    return {
      user: { name: "", password: "" }
    };
  },
  methods: {
    lgoin: function() {
      var that = this;
      axios.post("/api/user/login", that.user).then(function(response) {
        var data = response.data;
        if (data.code == 200) {
          //成功 跳转到用户中心
          that.$router.push({
            path: "/user/center"
          });
        } else {
          alert("用户名或密码出错！");
        }
      });
    }
  }
};
</script>
